home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_097 / shm / shm.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  257 lines

  1. /************************************************************************
  2.                  SHM.C V1.42 Copyright 1987 C.Ediss         8th August 87
  3. ************************************************************************/
  4. /* The default pattern takes about 3.4 minutes to generate */
  5.  
  6. #include <intuition/intuition.h>
  7. #include <float.h>
  8. #include <math.h>
  9.  
  10. #include "shm_defines"
  11.  
  12. extern struct Menu *SHMenu;
  13. extern void manual(),future(),parms(),palette();
  14. extern int cycle_time();
  15.  
  16. struct IntuitionBase *IntuitionBase;
  17. struct GfxBase *GfxBase;
  18. struct Screen *CustScr;
  19. struct Window *Wdw;
  20. struct IntuiMessage *message;
  21. struct ViewPort *WVP;
  22.  
  23. USHORT col1[16] =
  24.    {
  25.    0x000,0xFFF,0xF70,0x008,0xE66,0xFAB,0xFDB,0xFC0,
  26.    0xFF2,0xCF0,0x5D0,0x7DF,0x6AF,0xD0E,0xF2E,0x00F
  27.    };
  28. USHORT col2[16];
  29.  
  30. struct TextAttr Fnt =
  31. {
  32. "topaz.font",
  33. TOPAZ_EIGHTY,
  34. FS_NORMAL,
  35. FPF_ROMFONT
  36. };
  37.  
  38. int hc = 345, hcd = 345,      /* horizontal centre */
  39.     vc = 115, vcd = 115,      /* vertical centre   */
  40.     hs = 237, hsd = 237,      /* horizontal size   */
  41.     vs = 75,  vsd = 75;       /* vertical size     */
  42.  
  43. double hpp = 2, hppd = 2,         /* horizontal primary phase   */
  44.        vpp = 0, vppd = 0,         /* vertical primary phase     */
  45.        hsp = 1, hspd = 1,         /* horizontal secondary phase */
  46.        vsp = 2, vspd = 2,         /* vertical secondary phase   */
  47.        di = .00008, did = .00008, /* decay increment            */
  48.        sf = 2.04, sfd = 2.04,     /* secondary frequency        */
  49.        cp = 0.4, cpd = 0.4;       /* coupling                   */
  50.  
  51. struct NewScreen NewCustScr =
  52.    {
  53.    0,0,               /* Left, Top */
  54.    XMAX,YMAX,4,       /* Width, Height, Depth */
  55.    0,1,               /* DetailPen, BlockPen */
  56.    HIRES,             /* No INTERLACE */
  57.    CUSTOMSCREEN,      /* Screen Type */
  58.    &Fnt,              /* Pointer to custom font */
  59.    NL,                /* Pointer to screen title */
  60.    NL,                /* Pointer to screen gadgets */
  61.    NL,                /* Pointer to CustomBitMap */
  62.    };
  63.  
  64. struct NewWindow NewWdw =
  65.    {
  66.    0,0,                         /* Left Top */
  67.    XMAX,YMAX,                   /* Width Height */
  68.    0,1,                         /* Detail Block */
  69.    MENUPICK | ACTIVEWINDOW | REQCLEAR | INTUITICKS,
  70.    ACTIVATE | BORDERLESS | REPORTMOUSE,
  71.    NL,                          /* Pointer to first gadget */
  72.    NL,                          /* Pointer to check mark image */
  73.    "  SHM V1.42 Copyright 1987 C.Ediss. All Rights Reserved.",
  74.    NL,    /* Pointer to screen structure, dummy */
  75.    NL,    /* Pointer to custom bit map */
  76.    0,0,   /* Minimum width, height */
  77.    0,0,   /* Maximum width, height */
  78.    CUSTOMSCREEN  /* Type of screen it resides on */
  79.    };
  80.  
  81. /************************************************************************
  82.                          Fast Cosine Data Table
  83. ************************************************************************/
  84. double c[91] =
  85.                {1.000,.9998,.9994,.9986,.9976,.9962,
  86.                 .9945,.9925,.9903,.9877,.9848,.9816,
  87.                 .9781,.9744,.9703,.9659,.9613,.9563,
  88.                 .9511,.9455,.9397,.9336,.9272,.9205,
  89.                 .9135,.9063,.8988,.8910,.8829,.8746,
  90.                 .8660,.8572,.8480,.8387,.8290,.8191,
  91.                 .8090,.7986,.7880,.7771,.7660,.7547,
  92.                 .7431,.7313,.7193,.7071,.6946,.6820,
  93.                 .6691,.6560,.6428,.6293,.6156,.6018,
  94.                 .5878,.5735,.5592,.5446,.5299,.5150,
  95.                 .5000,.4848,.4694,.4540,.4383,.4226,
  96.                 .4067,.3907,.3746,.3583,.3420,.3255,
  97.                 .3090,.2923,.2756,.2588,.2419,.2249,
  98.                 .2079,.1908,.1736,.1564,.1391,.1218,
  99.                 .1045,.0871,.0697,.0523,.0348,.0174,0.0};
  100.  
  101. /************************************************************************
  102.                            Fast Cosine Function
  103. ************************************************************************/
  104. double cs(z)
  105. double z;
  106. {
  107. int a;
  108.    z/=TWOPI;
  109.    a=(int) 359*(z-floor(z));
  110.    if (a<=90) return(c[a]);
  111.    else if (a<=180) return(-c[180-a]);
  112.    else if (a<=270) return(-c[a-180]);
  113.    return(c[360-a]);
  114. }
  115.  
  116. /************************************************************************
  117.                             The Main Program
  118. ************************************************************************/
  119. void main()
  120. {
  121.    int class,code,cycle,cycle_time(),draw,i,inum,k,mnum,run,snum,
  122.        tc,ti,x,y;
  123.    double clr,cs(),t,amp;
  124.    USHORT ct;
  125.    void cleanup();
  126.  
  127.    clr = 0;
  128.    for (i=0; i<16; i++) col2[i] = col1[i];
  129.    cycle = 0;        /* Cycle flag */
  130.    draw = 1;         /* Draw flag */
  131.    run = 1;          /* Run flag */
  132.    t = 0;            /* Time */
  133.    tc = 2;           /* Cycle time */
  134.    ti = 0;           /* Tick counter */
  135.    amp=1;            /* Amplitude */
  136.  
  137.    IntuitionBase = (struct IntuitionBase *)
  138.          OpenLibrary("intuition.library",0);
  139.    if (IntuitionBase == NL) cleanup();
  140.  
  141.    GfxBase = (struct GfxBase *)
  142.          OpenLibrary("graphics.library",0);
  143.    if (GfxBase == NL) cleanup();
  144.  
  145.    if ((NewWdw.Screen = CustScr =
  146.    (struct Screen *)OpenScreen(&NewCustScr)) == NL) cleanup();
  147.  
  148.    if (( Wdw =
  149.    (struct Window *)OpenWindow(&NewWdw)) == NL) cleanup();
  150.  
  151. WVP = (struct ViewPort *)ViewPortAddress(Wdw);
  152. LoadRGB4(WVP,&col1,16); /* Load our new colors */
  153.  
  154. SetMenuStrip(Wdw,SHMenu);
  155.  
  156. while (run)
  157.       {
  158.       if ((draw>0) && (amp>=0))
  159.          {
  160.          t += DT;                          /* Time incremented */
  161.          clr += DT;              /* Colour counter incremented */
  162.          if (clr>=TWOPI) clr -= TWOPI;         /*  0<col<TWOPI */
  163.          k = (int) 15-floor(12*clr/TWOPI);  /*  Current colour */
  164.          SetAPen(RP,k);
  165.          amp -= di;                  /* Make amplitude smaller */
  166.          x = (int)hc + hs*amp*(cp*cs(sf*t+hsp)+cs(t+hpp));
  167.          y = (int)vc + vs*amp*(cp*cs(sf*t+vsp)+cs(t+vpp));
  168.          WritePixel(RP,x,y);                   /* Plot a point */
  169.          } /* draw */
  170.  
  171.       if ((cycle>0) && (ti>=tc))
  172.          {
  173.          ct = col1[15];
  174.          for (x=15; x>4; x--) col1[x]=col1[x-1];
  175.          col1[4] = ct;
  176.          LoadRGB4(WVP,&col1,16);          /* Cycle the colours */
  177.          ti = 0;
  178.          } /* cycle */
  179.  
  180.       while ((message = (struct IntuiMessage *)
  181.                         GetMsg (Wdw->UserPort)))
  182.          {
  183.          class = message->Class;
  184.          code = message->Code;
  185.          mnum = MENUNUM(code);
  186.          inum = ITEMNUM(code);
  187.          snum = SUBNUM(code);
  188.          ReplyMsg(message);
  189.          if ((class == INTUITICKS) && cycle) ti += 1;
  190.          if (class == MENUPICK)
  191.                {
  192.             if ((code) != MENUNULL)
  193.                {
  194.                switch (mnum)
  195.                       {
  196.                       case 0 : switch (inum)
  197.                                       {
  198.                                       case 0 : draw=1;
  199.                                                cycle=0;
  200.                                                break;
  201.                                       case 1 : draw=0;
  202.                                                cycle=0;
  203.                                                break;
  204.                                       case 2 : draw=0;
  205.                                                cycle=0;
  206.                                                clr = 0; 
  207.                                                t=0;
  208.                                                amp = 1;
  209.                                                break;  
  210.                                       case 3 : draw=0;
  211.                                                cycle=1;
  212.                                                break;
  213.                                       case 4 : draw = 0;
  214.                                                cycle = 0;
  215.                                                SetAPen(RP,0);
  216.                                                RectFill(RP,0,0,XMAX-1,YMAX-1);
  217.                                                SetAPen(RP,k);
  218.                                                break;
  219.                                       case 5 : manual(Wdw);
  220.                                                break;
  221.                                       case 6 : future(Wdw);
  222.                                                break;
  223.                                       case 7 : run=0;
  224.                                       }
  225.                                break;
  226.                       case 1 : switch (inum)
  227.                                {
  228.                                case 0 : parms(Wdw);
  229.                                         break;
  230.                                } /* ITEMNUM switch */
  231.                                break;
  232.                       case 2 : switch (inum)
  233.                                {
  234.                                case 0 : palette(Wdw);
  235.                                         break;
  236.                                case 1 : tc=cycle_time(Wdw,tc);
  237.                                } /* ITEMNUM switch */
  238.                       } /* MENUNUM switch */  
  239.                } /* != MENUNULL if */
  240.             } /* MENUPICK if */
  241.          } /* message while */
  242.       } /* while run */
  243. cleanup();
  244. }
  245.  
  246. /************************************************************************
  247.                             Cleanup Resources
  248. ************************************************************************/
  249. void cleanup()
  250. {
  251. if (Wdw != NL) CloseWindow(Wdw);
  252. if (CustScr != NL) CloseScreen(CustScr);
  253. if (GfxBase != NL) CloseLibrary(GfxBase);
  254. if (IntuitionBase != NL) CloseLibrary(IntuitionBase);
  255. exit(FALSE);
  256. }
  257.